package com.kzw.oa.system.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 组织机构
 */
@Entity
@Table(name = "organization")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Department implements Serializable {
	private static final long serialVersionUID = -7540578933177945363L;

	public final static Long PUBLIC_COMPANY_ID = new Long(-1);

	/**
	 * 集团
	 */
	public final static Short ORG_TYPE_GROUP = 0;
	/**
	 * 公司
	 */
	public final static Short ORG_TYPE_COMPANY = 1;
	/**
	 * 部门
	 */
	public final static Short ORG_TYPE_DEPARTMENT = 2;
	/**
	 * 其他组织
	 */
	public final static Short ORG_TYPE_ORTHER_ORG = 3;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long depId;

	// 单位名称
	@Column(length = 100)
	private String depName;

	// 单位描述
	@Column
	private String orgDesc;

	// 父单位ID
	@Column
	private Long orgSupId;

	// 单位路径
	@Column
	private String path;

	// 单位级别：从1开始？
	@Column
	private Long depth;

	// 单位类型
	@Column
	private Integer orgType;

	// 机构代码
	@Column(name="code_", length = 50)
	private String code;

	// 创建者ID
	@Column
	private Long creatorId;

	// 创建时间
	@Column
	private Date createtime;

	// 更新者ID
	@Column
	private Long updateId;

	// 更新时间
	@Column
	private Date updatetime;

	// 序号
	@Column
	private Integer sn; 

	// 用户与组织之间的多对多关系（管理者）
	@JsonIgnore
	@OneToMany(mappedBy = "dept")
	private Set<UserOrg> userOrgs = new HashSet<UserOrg>();

	public Department() {
	}

	public Department(Long orgId) {
		this.depId = orgId;
	}

	public Set<UserOrg> getUserOrgs() {
		return userOrgs;
	}

	public void setUserOrgs(Set<UserOrg> in_userOrgs) {
		this.userOrgs = in_userOrgs;
	}

	public Long getDepId() {
		return depId;
	}

	public void setDepId(Long depId) {
		this.depId = depId;
	}

	public String getDepName() {
		return depName;
	}

	public void setDepName(String depName) {
		this.depName = depName;
	}

	public String getOrgDesc() {
		return orgDesc;
	}

	public void setOrgDesc(String orgDesc) {
		this.orgDesc = orgDesc;
	}

	public Long getOrgSupId() {
		return this.orgSupId;
	}

	public void setOrgSupId(Long aValue) {
		this.orgSupId = aValue;
	}

	public String getPath() {
		return this.path;
	}

	public void setPath(String aValue) {
		this.path = aValue;
	}

	public Long getDepth() {
		return this.depth;
	}

	public void setDepth(Long aValue) {
		this.depth = aValue;
	}

	public Integer getOrgType() {
		return this.orgType;
	}

	public void setOrgType(Integer aValue) {
		this.orgType = aValue;
	}

	public Long getCreatorId() {
		return this.creatorId;
	}

	public void setCreatorId(Long aValue) {
		this.creatorId = aValue;
	}

	public Date getCreatetime() {
		return this.createtime;
	}

	public void setCreatetime(Date aValue) {
		this.createtime = aValue;
	}

	public Long getUpdateId() {
		return this.updateId;
	}

	public void setUpdateId(Long aValue) {
		this.updateId = aValue;
	}

	public Date getUpdatetime() {
		return this.updatetime;
	}

	public void setUpdatetime(Date aValue) {
		this.updatetime = aValue;
	}

	public Integer getSn() {
		return sn;
	}

	public void setSn(Integer sn) {
		this.sn = sn;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

}
